package edu.cmu.vlis.wassup;

import java.util.HashMap;
import java.util.Map;

/**
 * This class is needed as process starting procedure by Process Manager
 * is bit complicated. Given a poller id, this class knows how to 
 * instantiate appropriate poller and then run it. 
 */
public class ProcessFactory {


    
    public static void main(String[] args) {
        
        System.out.println("Trying to start a process.");
        String pollerId = args[0];
        String Id = args[1];
        Map<String,String> classNames = new HashMap<String, String>(2);
        classNames.put("10000", "edu.cmu.vlis.wassup.publisher.UpcomingPoller");
        classNames.put("20000", "edu.cmu.vlis.wassup.publisher.UserEventPoller");
        classNames.put("30000", "edu.cmu.vlis.wassup.sender.MessageProcessor");

        try {
            IProcess process = (IProcess) Class.forName(classNames.get(pollerId)).newInstance();
            System.out.println("Successfully started: "+classNames.get(pollerId));
            process.start(Id);   
            System.out.flush();
                    // Interestingly, System.out stream is lost at this point, though poller can still use it.
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } 
          }
    }
    
